package b3.widget.home.operation
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.scene.*;
	import b3.scene.build.*;
	import b3.scene.home.*;
	import b3.scene.home.grid.*;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	import b3.widget.guide.*;
	
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;

	public class WeaponSelectItem extends Sprite
	{
		private var buildingModel:BuildingModel;
		private var target:BuildingModel;
		
		public function WeaponSelectItem(buildingModel:BuildingModel, target:BuildingModel)
		{
			super();
			this.buildingModel = buildingModel;
			this.target = target;
			var buildingConfig:BuildingConfig = Config.buildingConfigs[buildingModel.buildingIndex];
			//背景框
			var TabItemBackground:Class = ResourceHelper.getInstance().getClassByName("TabItemBackground");
			var tabItemBackground:Sprite = new TabItemBackground();
			addChild(tabItemBackground);
			//图片
			var WeaponImage:Class = ResourceHelper.getInstance().getClassByName(buildingConfig.iconImage[buildingModel.roofType]);   
			var img:Sprite = new WeaponImage();
			img.x = (this.width - img.width) / 2;
			img.y = 88 - img.height;
			addChild(img);
			new Reflect({mc:img, alpha:50, ratio:80, distance:8, updateTime:-1, reflectionDropoff:1});
			//标题名字
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.LEFT;
        	if (buildingConfig.name.length < 6)
        	{
        		titleText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x0088FF, true);
        	}
        	else
        	{
        		titleText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x0088FF, true);
        	}
			titleText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleText.text = buildingConfig.name;
			titleText.x = (tabItemBackground.width - titleText.width) / 2;
			titleText.y = 85;
			addChild(titleText);
			//人口
			var PopulationIcon:Class = ResourceHelper.getInstance().getClassByName("PopulationIcon");
			var populationIcon:Sprite = new PopulationIcon();
			populationIcon.height = 20;
			populationIcon.scaleX = populationIcon.scaleY;
			populationIcon.x = 5;
			populationIcon.y = 8;
			addChild(populationIcon);
			//人口值
			var populationText:TextField = new TextField();
			populationText.selectable = false;
        	populationText.autoSize = TextFieldAutoSize.LEFT;
    		populationText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x0088FF, true);
			populationText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			populationText.text = BFont.formatNumWithComa(buildingModel.population);
			populationText.x = populationIcon.x + 20;
			populationText.y = 8;
			addChild(populationText);
			this.mouseChildren = false;
			addEventListener(MouseEvent.CLICK, onMouseClick);
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}

		private function onMouseClick(event:MouseEvent):void
		{
			var town:Town = HomeScene.getInstance().getCurrentTown();
			town.owner.townModel.attackBuilding(buildingModel, target);
		}

		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
		}    
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
		}
		
	}
}